package P_2023_03_06_String;

import java.util.Scanner;

public class StringTest2 {
    public static void main(String[] args) {
        //1.把1234数字转换成大写数字  壹贰叁肆伍陆柒捌玖
        //test1();

        //2.手机号屏蔽
        //test2();

        //3.身份证信息提示
        //test3();

        //4.敏感词替换
        test4();
    }

    //1.数字转大写
    public static void test1() {
        //1.键盘录入一个金额
        Scanner sc = new Scanner(System.in);
        int money = 0;
        while (true) {
            System.out.println("请输入一个金额：");
            money = sc.nextInt();
            if (money >= 0 && money <= 9999999) {
                break;
            } else {
                System.out.println("金额无效！");
            }
        }

        String moneyStr = "";//表示钱的大写
        String[] capitalNumber = new String[]{"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};

        //得到money中的没一位数字，转成大写
        while (true) {
            int ge = money % 10;
            moneyStr = capitalNumber[ge] + moneyStr;
            money /= 10;
            if (money == 0) {
                break;
            }
        }
        System.out.println(moneyStr);

        //3.在前面补零， 够 7 为
        int count = 7 - moneyStr.length();
        for (int i = 0; i < count; i++) {
            moneyStr = "零" + moneyStr;
        }

        System.out.println(moneyStr);

        //4.插入单位
        String[] arr = new String[]{"佰", "拾", "万", "仟", "佰", "拾", "元"};

        String result = "";
        for (int i = 0; i < moneyStr.length(); i++) {
            char c = moneyStr.charAt(i);
            //把大写数字与单位拼接在一起
            result = result + c + arr[i];
        }

        //5.打印结果
        System.out.println(result);
    }

    //2.手机号屏蔽
    public static void test2() {
        //1.获得换手机号
        String phoneNumber = "12345678901";
        //2.获得手机号前四位
        String start = phoneNumber.substring(0, 3);
        //3.获得手机号后四位
        String end = phoneNumber.substring(7);
        //4.拼接并打印
        String result = start + "****" + end;
        System.out.println(result);
    }

    //3.身份证信息查询
    public static void test3() {
        //1.定义一个身份证号
        String id = "450269202301061234";
        //2.获得出生年月
        String year = id.substring(6, 10);
        String month = id.substring(10, 12);
        String day = id.substring(12, 14);

        System.out.println("任务信息为：");
        System.out.println("出生年月日：" + year + "年" + month + "月" + day + "日");

        //3.判断性别
        char gender = id.charAt(16);
        int num = gender - 48;
        if (num % 2 == 0) {
            System.out.println("性别为：女");
        } else {
            System.out.println("性别为：男");
        }
    }

    //4.敏感词替换
    public static void test4() {
        //1.获取说的话
        String talk = "你游戏大的真好，下次别玩了，sb,tmd";

        //2.定义一个敏感词库
        String[] arr = new String[]{"cnm", "sb", "tmd"};

        //3.得到敏感词并替换
        for (int i = 0; i < arr.length; i++) {
            talk = talk.replace(arr[i], "***");
        }

        System.out.println(talk);

    }


}
